package com.xyy.yueshijia.view.activity;



import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.ViewGroup;

import com.superrecycleview.superlibrary.recycleview.SuperRecyclerView;
import com.xyy.yueshijia.R;
import com.xyy.yueshijia.bean.shop.StoreDatas;
import com.xyy.yueshijia.bean.shop.StoreGoods;
import com.xyy.yueshijia.bean.shop.StoreNews_special;
import com.xyy.yueshijia.presenter.GoodsSpeciaPresenter;
import com.xyy.yueshijia.view.impl.GoodsSpecialView;
import com.xyy.yueshijia.view.store.SpecialHeadViewHolder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SpecialActivity extends MvpActivity<GoodsSpeciaPresenter>
        implements GoodsSpecialView ,SuperRecyclerView.LoadingListener{

    private SuperRecyclerView mSuperRecyclerView;
    private SpecialGoodsAdapter mSpecialGoodsAdapter;
    //数据源
    private List<StoreGoods> mStoreGoodsList = new ArrayList<>();

    @Override
    protected GoodsSpeciaPresenter initPresenter() {
        return new GoodsSpeciaPresenter();
    }
    @Override
    protected void initData() {
        presenter.getGoodsSpecialDatas(getRequestParams());
    }
    @Override
    protected void initView() {
        mSuperRecyclerView = (SuperRecyclerView) findViewById(R.id.special_super_recyclerView);
//        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//        layoutManager.setOrientation(new linear);
        mSuperRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mSuperRecyclerView.setRefreshEnabled(true);//可以定制是否开启下拉刷新
        mSuperRecyclerView.setLoadMoreEnabled(false);//可以定制是否开启加载更多
//        mSuperRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);//可以自定义下拉刷新的样式
//        superRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallClipRotate);//可以自定义上拉加载的样式



        mSpecialGoodsAdapter = new SpecialGoodsAdapter(this,mStoreGoodsList);
        mSuperRecyclerView.setAdapter(mSpecialGoodsAdapter);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_special;
    }

    @Override
    public void onSuccess(StoreDatas storeDatas) {
        int size = storeDatas.getStoreNews_specialList().size();
        List<StoreNews_special> storeNews_specialList = storeDatas.getStoreNews_specialList();
        //
        List<StoreGoods> storeGoodsList = storeNews_specialList.get(1).getStoreGoodsList();
        mStoreGoodsList.addAll(storeGoodsList);
        mSpecialGoodsAdapter.notifyDataSetChanged();
        SpecialHeadViewHolder specialHeadViewHolder = new SpecialHeadViewHolder(this,(ViewGroup)this.getWindow().getDecorView(),storeDatas);
        mSpecialGoodsAdapter.addHeaderView(specialHeadViewHolder.getmHeadView());
    }

    @Override
    public void onShow() {

    }

    @Override
    public void onFial(Throwable throwable) {

    }

    @Override
    public void onFinish() {

    }

    public Map<String, String> getRequestParams() {

        HashMap<String, String> map = new HashMap<>();
       //act=app
        // &op=goods_special_new
        // &v=2.1.2
        // &special_id=532
        // &req_time=1486714090852
        // &key=aa1fb8a20d852b140e4b8089170a509f
        // &channel=yingyongbao
        // &token=749a036dc06ae8b3a120848995a9f306
        // &client=android
        map.put("act","app");
        map.put("op","goods_special_new");
        map.put("v","2.1.2");
//        Log.i("tag","----special_id------"+getIntent().getStringExtra("special_id"));
        map.put("special_id",getIntent().getStringExtra("special_id"));
        map.put("req_time","1486714090852");
        map.put("key","aa1fb8a20d852b140e4b8089170a509f");
        map.put("channel","yingyongbao");
        map.put("token","749a036dc06ae8b3a120848995a9f306");
        map.put("client","android");
        return map;
    }

    @Override
    public void onRefresh() {
        mSuperRecyclerView.completeRefresh();
        mSpecialGoodsAdapter.notifyDataSetChanged();
    }

    @Override
    public void onLoadMore() {
        mSuperRecyclerView.completeLoadMore();
        mSpecialGoodsAdapter.notifyDataSetChanged();
    }
}
